//
//  YCEarningViewController.m
//  lianganyuchu
//
//  Created by iMac on 17/2/23.
//  Copyright © 2017年 杭州桑缇电子商务有限公司. All rights reserved.
//

#import "YCEarningViewController.h"

@interface YCEarningViewController ()
{
    UILabel *m_labMoney;
    UIButton *m_btnDetail;
    
    UILabel *m_labInocme;
    UILabel *m_labExpand;
}
@end

@implementation YCEarningViewController
-(void)viewWillAppear:(BOOL)animated
{
    [_naviVC setNaviHidden:NO];
    [_naviVC setMainNaviVC];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"营业数据";
    self.navigationItem.leftBarButtonItem=[self tbarBackButtonWhite];
    
    [self addMainView];
    [self loadData];
}
-(void)loadData
{
    StatisticsRequest *request = [StatisticsRequest new];
    [apiClient hideProgress];
    [apiClient disableAfterRequest];
    [apiClient doStatistics:request success:^(ApiResponse *data, NSString *url) {
        StatisticsResponse *response=[[StatisticsResponse alloc]initWithCGResponse:data];
        [m_labMoney setText:response.balance];
        
        NSMutableAttributedString *strIncome = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"   累计收入  %@",response.income_total]];
        [strIncome addAttribute:NSForegroundColorAttributeName value:TEXT_LIGHT range:NSMakeRange(0, 7)];
        [strIncome addAttribute:NSFontAttributeName value:[UIFont LightFontOfSize:17] range:NSMakeRange(0, 7)];
        [m_labInocme setAttributedText:strIncome];
        
        
        NSMutableAttributedString *strExpand = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"   累计支出  %@",response.outgo_total]];
        [strExpand addAttribute:NSForegroundColorAttributeName value:TEXT_LIGHT range:NSMakeRange(0, 7)];
        [strExpand addAttribute:NSFontAttributeName value:[UIFont LightFontOfSize:17] range:NSMakeRange(0, 7)];
        [m_labExpand setAttributedText:strExpand];

        
    }failure:^(ApiResponse *data, NSString *url){
    }];
}
-(void)addMainView
{
    self.view.backgroundColor=WHITE_COLOR;
    UIView *backView=[[UIView alloc]init];
    [backView setBackgroundColor:MAIN_COLOR];
    [self.view addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.top.equalTo(self.view).offset(kNAV_HEIGHT);
        make.height.mas_equalTo(150);
    }];
    
    UILabel *label=[[UILabel alloc]init];
    [label setTextColor:WHITE_COLOR];
    [label setFont:[UIFont LightFontOfSize:15]];
    [self.view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(2*kDistance);
        make.width.mas_equalTo(150);
        make.top.equalTo(self.view).offset(95);
        make.height.mas_equalTo(20);
    }];
    [label setText:@"账户余额（元）"];
    
    m_labMoney=[[UILabel alloc]init];
    [m_labMoney setTextColor:WHITE_COLOR];
    [m_labMoney setFont:[UIFont FontOfSize:32]];
    [self.view addSubview:m_labMoney];
    [m_labMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(2*kDistance);
        make.width.mas_equalTo(300);
        make.top.equalTo(label.bottom).offset(35/2);
        make.height.mas_equalTo(30);
    }];
    
    
    m_btnDetail=[[UIButton alloc]init];
    m_btnDetail.layer.cornerRadius=2.0f;
    m_btnDetail.layer.borderWidth=1.0f;
    m_btnDetail.layer.borderColor=MAIN_COLOR.CGColor;
    [m_btnDetail setTitle:@"查看明细" forState:UIControlStateNormal];
    [m_btnDetail setTitleColor:MAIN_COLOR forState:UIControlStateNormal];
    [m_btnDetail setBackgroundColor:WHITE_COLOR];
    [m_btnDetail.titleLabel setFont:[UIFont LightFontOfSize:16]];
    [self.view addSubview:m_btnDetail];
    [m_btnDetail addTarget:self action:@selector(buttonDetailClicked:) forControlEvents:UIControlEventTouchUpInside];
    [m_btnDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-25);
        make.width.mas_equalTo(120);
        make.bottom.equalTo(backView).offset(10);
        make.height.mas_equalTo(40);
    }];
    
    m_labInocme=[[UILabel alloc]init];
    [m_labInocme setTextColor:TEXT_DEEP];
    [m_labInocme setFont:[UIFont LightFontOfSize:18]];
    [self.view addSubview:m_labInocme];
    [m_labInocme addShadowWith:CGSizeMake(W(self.view)-2*kDistance, 50)];
    [m_labInocme setBackgroundColor:WHITE_COLOR];
    [m_labInocme mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-kDistance);
        make.left.equalTo(self.view).offset(kDistance);
        make.top.equalTo(m_btnDetail.bottom).offset(kDistance);
        make.height.mas_equalTo(50);
    }];
    
    
    m_labExpand=[[UILabel alloc]init];
    [m_labExpand setTextColor:TEXT_DEEP];
    [m_labExpand setFont:[UIFont LightFontOfSize:18]];
    [self.view addSubview:m_labExpand];
    [m_labExpand addShadowWith:CGSizeMake(W(self.view)-2*kDistance, 50)];
    [m_labExpand setBackgroundColor:WHITE_COLOR];
    [m_labExpand mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-kDistance);
        make.left.equalTo(self.view).offset(kDistance);
        make.top.equalTo(m_labInocme.bottom).offset(kDistance);
        make.height.mas_equalTo(50);
    }];
}
-(void)buttonDetailClicked:(UIButton *)button
{
    YCTotalEarningViewController *totalVC=[[YCTotalEarningViewController alloc]init];
    [self showNavigationView:totalVC];
}


@end






